<?php

use yii\db\Migration;

class m000005_000003_create_card_bill extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%card_bill}}', [
            'id' => $this->primaryKey(),
            'card_id' => $this->integer()->notNull()->comment('卡编号'),
            'start_time' => $this->integer()->notNull()->comment('开始时间'),
            'end_time' => $this->integer()->notNull()->comment('结束时间'),
            'money' => $this->decimal(20, 4)->notNull()->defaultValue(0)->comment('金额'),
            'create_time' => $this->integer()->notNull()->comment('创建时间'),
        ]);
        $this->createIndex('fk_card_bill_card1_idx', '{{%card_bill}}', ['card_id']);
        try {
            $this->addForeignKey('fk_card_bill_card1', '{{%card_bill}}', ['card_id'], '{{%card}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
    }

    public function down()
    {
        $this->dropTable('{{%card_bill}}');
    }
}
